package com.r_z.controller;

import com.r_z.entity.Outbound;
import com.r_z.entity.OutboundDetails;
import com.r_z.result.CommonResult;
import com.r_z.service.OutboundService;
import com.r_z.util.RequestMsg;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出库操作的控制层
 * @author 任俊杰
 * @version 1.0
 * @date 2023/5/29
 */
@CrossOrigin
@RestController
public class OutboundController {
    //出库 service 类
    @Resource
    private OutboundService outboundService;

    /**
     * 查询出库信息
     * @param page 当前页
     * @param limit 每页显示数
     * @param nowTime 当前时间
     * @return
     */
    @GetMapping("/selectOutbound")
    public CommonResult<Outbound>selectOutbound(Integer page,Integer limit,String nowTime){
        System.out.println("进来了查询出库信息的方法");
        //查询出库信息
        List<Outbound> outboundList = outboundService.selectOutbound(page, limit, nowTime);
        for (Outbound outbound : outboundList) {
            System.out.println(outbound.getSalesOrderId()+"\t"+outbound.getNowTime()+"\t"+outbound.getTotalNum()+"\t"+outbound.getState());
        }
        //查询出库行数信息
        int count = outboundService.getTotal(nowTime);
        System.out.println(count);
        return RequestMsg.msg(count,outboundList);
    }

    /**
     * 查询出库详情数据
     * @param salesOrderId 销售id
     * @return 详情数据
     */
    @GetMapping("/selectDetails")
    public CommonResult<OutboundDetails>selectDetails(String salesOrderId){
        System.out.println("进来了库存出库详情的方法");
        OutboundDetails outboundDetails = outboundService.selectDetails(salesOrderId);
        return RequestMsg.msg(outboundDetails);
    }


    /**
     * 出库审核
     * @param salesOrderId 销售订单id
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @PostMapping("/auditOutbound")
    public CommonResult<Outbound>auditOutbound(String salesOrderId){
        System.out.println("进来了出库审核的方法"+salesOrderId);
        int i = outboundService.auditOutbound(salesOrderId);
        return RequestMsg.msg(i);//这里是返回工具类里的第一个还是第二个？
    }


}
